const { BusiError, SysError } = require('../exception/exception');
const rsa = require('../encode/Rsa');
const config = require('../config/config');
const axi = require('axios');
const uuidUtil = require('../util/uuidUtil');
const xmlUtil = require('../util/xmlUtil');
const dateUtil = require('../util/dateUtil');
const stringUtil = require('../util/stringUtil');
const idUtil = require('../util/idUtil');
const payOrderDao = require('../dao/payOrderDao');
const payAcctDao = require('../dao/payAcctDao');
const userDao = require('../dao/userDao');
const mysqlPool = require('../dao/MySQLPool');
const exchangeDao = require('../dao/exchangeDao');
let md5 = require('md5');

const busiConst = require('../const/busiConst');
const payConst = require('../const/payConst');

const axiosConfig = {
    timeout: 15000,
    baseURL: config.conf["pay.mdf.baseUrl"],
};

const axios = axi.create(axiosConfig);

class MdfUnionPayService {
    constructor() {
        this.payChannel = "J005";
        this.notifyUrl = config.conf["pay.mdf.notifyUrl"] + "/mdf";
        this.service = "pay.mdf.withdraw";
        this.mchId = config.conf["pay.mdf.mchId"];
        this.key = config.conf["pay.mdf.key"];
    }

    /**
     * 
     * @param {String} flowNo 
     */
    async withdraw(flowNo, remark, operator){
        let eo = await exchangeDao.getRecordByFlowNo(flowNo);
        if(!eo){
            throw new BusiError(500, "查无此订单:" + flowNo);
        }

        let payAcct = await payAcctDao.get({uid: eo.uid, type: eo.type});
        if(!payAcct){
            throw new BusiError(500, "该账号未绑定银行卡:" + eo.uid + ", 请绑定后再提现");
        }

         /*
        商户ID	mchId	是	long	20001222
        商户代付单号	mchOrderNo	是	String(30)	20160427210604000490
        代付金额	amount	是	int	8000
        账户属性	accountAttr	否	Byte	0
        收款人账户名	accountName	是	String(64)	
        manager收款人账户号	accountNo	是	Number	6222020200098541458
        开户行所在省份	province	否	String(32)	
        北京开户行所在市	city	否	String(32)	
        北京开户行名称	bankName	否	String(128)	
        北京上地支行联行号	bankNumber	否	String(64)	11473707055
        代付结果回调URL	notifyUrl	否	String(128)	http://www.baidu.com
        备注	remark	是	String(128)	
        代付1000元扩展域	extra	否	String(128)	
        请求时间	reqTime	是	String(20)	20181009171032
        用户ID	uid	false	long	123445
        用户的ip	cip	false	String(20)	172.13.45.11
        签名	sign	是	String(32)	C380BEC2BFD727A4B6845133519F3AD6*/

        let amt = Math.floor(eo.real_ex_amt * 100);
        let payEntity = {
            mchId: this.mchId,
            mchOrderNo: flowNo,
            amount: amt,
            accountName: payAcct.realname,
            accountNo: payAcct.acct_no,
            remark: "操作员[" + operator + "],remark[" + remark + "]",
            reqTime: dateUtil.dateFormatYMDHMSNoToken()
        };

        let expireTime = new Date();//你已知的时间
        let timestamp = expireTime.getTime();//转化为时间戳毫秒数
        expireTime.setTime(timestamp + 1000 * 60 * 60 * 24);// 一天时间超时

        let order = {
            uid: eo.uid,
            payChannel: this.payChannel,
            amount: amt,
            outTradeNo: flowNo,
            payOrderType: payConst.ORDER_TYPE_WITHDRAW,
            tradeType: this.service,
            expireTime: expireTime
        };

        let saveOrderId = await payOrderDao.save(order);
        if (saveOrderId <= 0) {
            throw new BusiError(500, "创建订单失败");
        }

        let queryStr = stringUtil.getSignStr(payEntity);
        let signStr = queryStr + "&key=" + this.key;
        signStr = md5(signStr).toUpperCase();
        queryStr += "&sign=" + signStr;
        queryStr = encodeURI(queryStr);

        let resp = await axios.get("/apply?" + queryStr);
        console.logw("请求返回报文:", resp.data);
        let data = resp.data;
        // retCode:"FAIL"
        // retMsg:"IP[124.160.217.243]不允许访问"
        if(data.retCode !== "SUCCESS"){
            order.errCode = data.retCode;
            order.errMsg = data.retMsg;
            order.status = payConst.payOrderStatus.orderClose;
            let updateRes = await payOrderDao.updateByOutTradeNo(order);
            if (updateRes <= 0) {
                console.log("更新订单异常信息出错:", order);
                throw new BusiError(500, "更新订单异常信息出错");
            }
            throw new BusiError(500, "交易通信异常:" + order.errMsg);
        }

        let tradeNo = data.agentpayOrderId;
        order.tradeNo = tradeNo;
        let mchTradeNo = data.mchOrderNo;
        order.ext1 = mchTradeNo;
       
        let fee = data.fee;
        order.ext2 = fee;
        let status = data.status;
        order.errCode = status;

        let updateRes = await payOrderDao.updateByOutTradeNo(order);
        if (updateRes <= 0) {
            console.log("更新订单异常信息出错:", order);
            throw new BusiError(500, "更新订单异常信息出错");
        }
    }

    async withdrawQuery(flowNo){
        /*
        商户ID	mchId	是	long	1000000010	分配的商户号
商户订单号	mchOrderNo	是	String(30)	AP1538919309174	商户生成的订单号，与agentpayOrderId二者传一即可
代付订单号	agentpayOrderId	是	String(30)	G01201810070935094340418	支付中心生成的订单号，与mchOrderNo二者传一即可
请求时间	reqTime	是	String(20)	20181009171032	请求发起时间,时间格式:yyyyMMddHHmmss
签名	sign	是	String(32)	C380BEC2BFD727A4B6845133519F3AD6	签名值，详见签名算法
*/
        let order = await payOrderDao.getByOutTradeNo(flowNo);
        if(!order){
            throw new BusiError(500, "查无此订单:" + flowNo);
        }

        let eo = await exchangeDao.getRecordByFlowNoAndStatus(flowNo, 1);
        if(!eo){
            throw new BusiError(500, "查无此订单:" + flowNo);
        }

        let queryEntity = {
            mchId: this.mchId,
            mchOrderNo: flowNo,
            reqTime: dateUtil.dateFormatYMDHMSNoToken,
        };

        let queryStr = stringUtil.getSignStr(queryEntity);
        let signStr = queryStr + "&key=" + this.key;
        signStr = md5(signStr).toUpperCase();
        queryStr += "&sign=" + signStr;
        queryStr = encodeURI(queryStr);

        let resp = await axios.get("/queryOrde?" + queryStr);
        console.logw("请求返回报文:", resp.data);
        let data = resp.data;
        let msg = "";
        if(data.retCode !== "SUCCESS"){
            // 对超出截止日期5分钟的订单做处理
            // let expireTime = new Date(order.expire_time);
            // if (expireTime.getTime() + 1000 * 60 * 5 < new Date().getTime()) {
            //     order.status = payConst.payOrderStatus.orderClose;
            //     order.remark = "订单超时关闭";
            // }

            order.errCode = data.retCode;
            order.errMsg = data.retMsg;
            msg =  data.retCode + ":" + data.retMsg;
            let updateRes = await payOrderDao.updateByOutTradeNo(order);
            if (updateRes <= 0) {
                console.log("更新订单异常信息出错:", order);
                throw new BusiError(500, "更新订单异常信息出错:" + data.retMsg);
            }
            throw new BusiError(500, "交易失败:" + data.retMsg);
        }

        order.status = payConst.payOrderStatus.orderFailed;
        order.tradeState = data.status;
        if (data.status === 0 || data.status === 1) {
            order.status = payConst.payOrderStatus.orderInit;
        }

        if (data.status === 2) {
            order.status = payConst.payOrderStatus.orderSuccess;

            let tradeNo = data.agentpayOrderId;
            order.tradeNo = tradeNo;

            msg = data.transMsg;
            order.finishTime = new Date();
            eo.status = 2;
        }

        if(data.status === 3){
            eo.status = -2;
        }

        await mysqlPool.doWithTx(async function (conn) {
            let res2 = await payOrderDao.updateByOutTradeNoWithTx(conn, order);
            if (res2 < 1) {
                console.logw("更新订单失败:", order);
                throw new BusiError(500, "更新订单失败");
            }

            if(eo.status !== 1){
                let res = await exchangeDao.updateStatusWithTx(conn, {flowNo: flowNo, status: eo.status});
                if (res < 1) {
                    console.logw("更新提现订单失败:", order);
                    throw new BusiError(500, "更新订单失败");
                }
            }

            if (order.status === payConst.payOrderStatus.orderSuccess) {
                let res1 = await userDao.releaseFreezeCoinWithTx(conn, order.uid, parseFloat(order.amount / 100.00).toFixed(2));
                if (res1 < 1) {
                    console.logw("inc user coin err: res1 <= 0");
                    throw new BusiError(500, "增加余额失败");
                }
            }
        });
    }

    /**
     *
     * @param {String} uid
     * @param {int} amount
     * @returns {Promise<void>}
     */
    async pay(uid, amount) {

        throw new BusiError(500, "暂未开通此通道支付[MDF]");

        // /*
        // 商户ID	mchId	是	long	20001222
        // 商户代付单号	mchOrderNo	是	String(30)	20160427210604000490
        // 代付金额	amount	是	int	8000
        // 账户属性	accountAttr	否	Byte	0
        // 收款人账户名	accountName	是	String(64)	
        // manager收款人账户号	accountNo	是	Number	6222020200098541458
        // 开户行所在省份	province	否	String(32)	
        // 北京开户行所在市	city	否	String(32)	
        // 北京开户行名称	bankName	否	String(128)	
        // 北京上地支行联行号	bankNumber	否	String(64)	11473707055
        // 代付结果回调URL	notifyUrl	否	String(128)	http://www.baidu.com
        // 备注	remark	是	String(128)	
        // 代付1000元扩展域	extra	否	String(128)	
        // 请求时间	reqTime	是	String(20)	20181009171032
        // 用户ID	uid	false	long	123445
        // 用户的ip	cip	false	String(20)	172.13.45.11
        // 签名	sign	是	String(32)	C380BEC2BFD727A4B6845133519F3AD6*/

        // let payEntity = {};
        // payEntity.mch_id = this.mchId;
        // let outTradeNo = busiConst.TYPE_RECHARGE_OUT_TRADE_NO + config.machineNo + dateUtil.dateFormat("yyyyMMddhhmmss", new Date())
        //     + stringUtil.padZeroSix(idUtil.nextSix());
        // payEntity.mchOrderNo = outTradeNo;
        // // payEntity.device_info = "00";
        // // payEntity.op_user_id = "jk";
        // // payEntity.op_shop_id = "id";
        // payEntity.body = "JKUnionOrder";
        // // payEntity.attach = "just_attach";
        // payEntity.total_fee = amount;
        // // payEntity.limit_credit_pay = 0;
        // payEntity.mch_create_ip = "127.0.0.1";
        // payEntity.notify_url = this.notifyUrl;
        // // payEntity.time_start = "20190331091010";
        // // payEntity.time_expire = "20190431091010";
        // let nonceStr = uuidUtil.uuid();
        // payEntity.nonce_str = nonceStr;
        // payEntity.callback_url = config.conf["pay.qft.callBackUrl"] + "?ts=" + new Date().getTime();
        // // payEntity.time_start = "";
        // // payEntity.time_expire = "";

        // let expireTime = new Date();//你已知的时间
        // let timestamp = expireTime.getTime();//转化为时间戳毫秒数
        // expireTime.setTime(timestamp + 1000 * 60 * 10);//设置新时间比旧时间多一小时
        // let expireTimeStr = dateUtil.dateFormat("yyyyMMddhhmmss", expireTime);
        // payEntity.time_expire = expireTimeStr;

        // let order = {
        //     uid: uid,
        //     payChannel: this.payChannel,
        //     amount: amount,
        //     outTradeNo: outTradeNo,
        //     payOrderType: payConst.ORDER_TYPE_RECHARGE,
        //     tradeType: this.service,
        //     expireTime: expireTime
        // };

        // let saveOrderId = await payOrderDao.save(order);
        // if (saveOrderId <= 0) {
        //     throw new BusiError(500, "创建订单失败");
        // }

        // order.id = saveOrderId;

        // let signStr = stringUtil.getSignStr(payEntity);
        // payEntity.sign = await rsa.sign256(signStr);

        // let jsonXml = xmlUtil.entity2xml(payEntity);
        // console.logw("创建订单请求报文:", jsonXml);

        // let json2 = await xmlUtil.xml2json(jsonXml);
        // let resp = await axios.post("", jsonXml);
        // let json = await xmlUtil.xml2json(resp.data);
        // console.logw("创建订单返回报文:", JSON.stringify(json));

        // if (json.xml.status !== '0') {
        //     order.errCode = json.xml.status;
        //     order.errMsg = json.xml.message;
        //     order.status = payConst.payOrderStatus.orderClose;
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错");
        //     }
        //     throw new BusiError(500, "交易通信异常");
        // }

        // if (json.xml.result_code !== '0') {
        //     console.logw("创建订单失败:", JSON.stringify(json));
        //     order.errCode = json.xml.err_code;
        //     order.errMsg = json.xml.err_msg;
        //     order.status = payConst.payOrderStatus.orderClose;
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错");
        //     }
        //     throw new BusiError(500, "交易失败");
        // }

        // //
        // let resSignStr = stringUtil.getSignStr(json.xml);
        // let isValid = await rsa.verify256(resSignStr, json.xml.sign);
        // if (!isValid) {
        //     console.logw("订单返回报文验签失败:", JSON.stringify(json));
        //     order.remark = "订单返回报文验签失败";
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错");
        //     }
        //     throw new BusiError(500, "验签失败");
        // }

        // return json.xml.pay_info;
    }

    async payNotify(notify) {
        throw new BusiError(500, "暂未开通此通道支付[MDF]");
        // if (!notify.xml) {
        //     console.log("receive pay notify err:", notify);
        //     throw new BusiError(500, "回调通知状态异常");
        // }

        // notify = notify.xml;
        // if (notify.status !== '0') {
        //     console.log("receive pay notify err[1]:", notify);
        //     throw new BusiError(500, "回调通知状态异常");
        // }

        // if (notify.result_code !== '0') {
        //     console.log("receive pay notify err[2]:", notify);
        //     throw new BusiError(500, "回调通知状态异常");
        // }

        // // out_trade_no
        // let order = await payOrderDao.getByOutTradeNo(notify.out_trade_no);
        // if (!order) {
        //     console.log("receive pay notify err[3], 查无此订单:", notify);
        //     throw new BusiError(500, "查无此订单");
        // }
        // order.outTradeNo = notify.out_trade_no;

        // if (order.status === payConst.payOrderStatus.orderSuccess) {
        //     console.log("此订单已经交易成功:", order);
        //     return;
        // }

        // let resSignStr = stringUtil.getSignStr(notify);
        // let isValid = await rsa.verify256(resSignStr, notify.sign);
        // if (!isValid) {
        //     console.logw("回调通知返回报文验签失败:", JSON.stringify(notify));
        //     order.errCode = notify.err_code;
        //     order.errMsg = notify.err_msg;
        //     order.remark = "订单返回报文验签失败";
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错");
        //     }
        //     throw new BusiError(500, "验签失败");
        // }

        // let payResult = notify.pay_result;
        // let timeEnd = notify.time_end;
        // if (!timeEnd) {
        //     order.finishTime = new Date();
        // } else {
        //     order.finishTime = dateUtil.yyyyMMddHHmmssToDate(timeEnd);
        // }
        // order.status = payConst.payOrderStatus.orderFailed;
        // if (payResult === "0") {
        //     order.status = payConst.payOrderStatus.orderSuccess;
        //     order.tradeNo = notify.transaction_id;
        //     order.bankType = notify.bank_type;
        // }

        // await mysqlPool.doWithTx(async function (conn) {
        //     let res2 = await payOrderDao.updateByOutTradeNoWithTx(conn, order);
        //     if (res2 < 1) {
        //         console.logw("更新订单失败:", order);
        //         throw new BusiError(500, "更新订单失败");
        //     }

        //     if (order.status === payConst.payOrderStatus.orderSuccess) {
        //         let res1 = await userDao.incCoinWithTx(conn, order.uid, parseFloat(order.amount / 100.00).toFixed(2));
        //         if (res1 < 1) {
        //             console.logw("inc user coin err: res1 <= 0");
        //             throw new BusiError(500, "增加余额失败");
        //         }
        //     }
        // });
    }

    async payQuery(outTradeNo) {
        throw new BusiError(500, "暂未开通此通道支付[MDF]");
        // let order = await payOrderDao.getByOutTradeNo(outTradeNo);
        // if (!order) {
        //     console.log("receive pay notify err[3], 查无此订单:", outTradeNo);
        //     throw new BusiError(500, "查询失败");
        // }
        // order.outTradeNo = outTradeNo;

        // if (order.status === payConst.payOrderStatus.orderSuccess) {
        //     console.log("此订单已经交易成功:", order);
        //     throw new BusiError(500, "此订单已经交易成功");
        // }

        // let queryEntity = {};
        // queryEntity.service = "unified.trade.query";
        // queryEntity.version = "2.0";
        // // payEntity.charset = "UTF-8";
        // queryEntity.sign_type = "RSA_1_256";
        // queryEntity.mch_id = this.mchId;
        // queryEntity.out_trade_no = outTradeNo;
        // queryEntity.nonce_str = uuidUtil.uuid();

        // let signStr = stringUtil.getSignStr(queryEntity);

        // let sign = await rsa.sign256(signStr);
        // queryEntity.sign = sign;

        // let jsonXml = xmlUtil.entity2xml(queryEntity);
        // console.logw("查询订单请求报文:", jsonXml);

        // let json2 = await xmlUtil.xml2json(jsonXml);
        // let resp = await axios.post("", jsonXml);
        // let json = await xmlUtil.xml2json(resp.data);
        // console.logw("查询订单返回报文:", JSON.stringify(json));

        // if (json.xml.status !== '0') {
        //     order.errMsg = json.xml.message;
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错:" + json.xml.err_msg);
        //     }
        //     throw new BusiError(500, "交易通信异常:" + json.xml.err_msg);
        // }

        // let msg = "";
        // if (json.xml.result_code !== '0') {
        //     console.logw("查询订单失败:", JSON.stringify(json));
        //     // 对超出截止日期5分钟的订单做处理
        //     let expireTime = new Date(order.expire_time);
        //     if (expireTime.getTime() + 1000 * 60 * 5 < new Date().getTime()) {
        //         order.status = payConst.payOrderStatus.orderClose;
        //         order.remark = "订单超时关闭";
        //     }

        //     order.errCode = json.xml.err_code;
        //     order.errMsg = json.xml.err_msg;
        //     msg = json.xml.err_code + ":" + json.xml.err_msg;
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错:" + json.xml.err_msg);
        //     }
        //     throw new BusiError(500, "交易失败:" + json.xml.err_msg);
        // }

        // //
        // let resSignStr = stringUtil.getSignStr(json.xml);
        // let isValid = await rsa.verify256(resSignStr, json.xml.sign);
        // if (!isValid) {
        //     console.logw("订单返回报文验签失败:", JSON.stringify(json));
        //     order.remark = "订单返回报文验签失败";
        //     let updateRes = await payOrderDao.updateByOutTradeNo(order);
        //     if (updateRes <= 0) {
        //         console.log("更新订单异常信息出错:", order);
        //         throw new BusiError(500, "更新订单异常信息出错");
        //     }
        //     throw new BusiError(500, "验签失败");
        // }

        // order.status = payConst.payOrderStatus.orderFailed;
        // order.tradeState = json.xml.trade_state;
        // if (json.xml.trade_state === 'USERPAYING') {
        //     order.status = payConst.payOrderStatus.orderInit;
        //     let expireTime = new Date(order.expire_time);
        //     if (expireTime.getTime() + 1000 * 60 * 5 < new Date().getTime()) {
        //         order.remark = "订单超时关闭";
        //         order.status = payConst.payOrderStatus.orderClose;
        //     }
        // }

        // if (json.xml.trade_state === 'SUCCESS') {
        //     order.status = payConst.payOrderStatus.orderSuccess;
        //     order.tradeNo = json.xml.transaction_id;
        //     if (!json.xml.time_end) {
        //         order.finishTime = new Date();
        //     } else {
        //         order.finishTime = dateUtil.yyyyMMddHHmmssToDate(json.xml.time_end);
        //     }
        //     order.bankType = json.xml.bank_type;
        // }

        // await mysqlPool.doWithTx(async function (conn) {
        //     let res2 = await payOrderDao.updateByOutTradeNoWithTx(conn, order);
        //     if (res2 < 1) {
        //         console.logw("更新订单失败:", order);
        //         throw new BusiError(500, "更新订单失败");
        //     }

        //     if (order.status === payConst.payOrderStatus.orderSuccess) {
        //         let res1 = await userDao.incCoinWithTx(conn, order.uid, parseFloat(order.amount / 100.00).toFixed(2));
        //         if (res1 < 1) {
        //             console.logw("inc user coin err: res1 <= 0");
        //             throw new BusiError(500, "增加余额失败");
        //         }
        //     }
        // });

        // return msg;
    }

    async refund(outTradeNo, refundAmt) {
        throw new BusiError(500, "暂未开通此通道支付[MDF]");
        // let refundEntity = {};
        // refundEntity.service = "unified.trade.refund";
        // // refundEntity.version = "1.0";
        // // refundEntity.charset = "UTF-8";
        // // refundEntity.sign_type = "MD5";
        // refundEntity.mch_id = this.mchId;
        // refundEntity.out_trade_no = outTradeNo;

        // // todo: create refund no
        // let outRefundNo = busiConst.TYPE_RECHARGE_OUT_REFUND_NO + config.machineNo + dateUtil.dateFormat("yyyyMMddhhmmss")
        //     + stringUtil.padZeroSix(idUtil.nextSix());
        // refundEntity.out_refund_no = outRefundNo;

        // // query db
        // let res = {};
        // refundEntity.total_fee = res.amount;
        // refundEntity.refund_fee = refundAmt;
        // refundEntity.op_user_id = this.mchId;
        // refundEntity.refund_channel = "ORIGINAL";
        // refundEntity.nonce_str = uuidUtil.uuid();


        // let signStr = stringUtil.getSignStr(refundEntity);
        // let sign = await rsa.sign256(signStr);
        // refundEntity.sign = sign;

        // let jsonXml = xmlUtil.entity2xml(refundEntity);
        // console.log("final str:", jsonXml);

        // let resp = await axios.post("", jsonXml);
        // console.log("data:", resp.data);

        // let json = await xmlUtil.xml2json(resp.data);
        // console.log(JSON.stringify(json));
    }

    async refundQuery(outRefundNo) {
        throw new BusiError(500, "暂未开通此通道支付[MDF]");
        // let refundQueryEntity = {};
        // refundQueryEntity.service = "unified.trade.refundquery";
        // // refundQueryEntity.version = "1.0";
        // // refundQueryEntity.charset = "UTF-8";
        // // refundQueryEntity.sign_type = "MD5";
        // refundQueryEntity.mch_id = this.mchId;
        // refundQueryEntity.out_refund_no = outRefundNo;
        // refundQueryEntity.nonce_str = uuidUtil.uuid();

        // let signStr = stringUtil.getSignStr(refundQueryEntity);
        // let sign = await rsa.sign256(signStr);
        // refundQueryEntity.sign = sign;

        // let jsonXml = xmlUtil.entity2xml(refundQueryEntity);
        // console.log("final str:", jsonXml);

        // let resp = await axios.post("", jsonXml);
        // console.log("data:", resp.data);


        // let json = await xmlUtil.xml2json(resp.data);
        // console.log(JSON.stringify(json));
    }
}

let mdfUnionPayService = new MdfUnionPayService();
module.exports =  mdfUnionPayService;